
SRC_DIR = ./src/
OBJ_DIR = ./obj/
HEADER_DIR = ./include/
LIB_DIR = ./lib/
INCUDLE_CONFIG = -I$(HEADER_DIR)
LIBRARY_CONFIG = -L$(LIB_DIR) -lole32 -ld2d1 -lwindowscodecs -lresource -ldwmapi -lGdi32 -lMfplat -lMf -lShlwapi -levr

RESOURCE_DIR = ./res/

HEAD = $(wildcard $(HEADER_DIR)*.h)
SRC = $(wildcard $(SRC_DIR)*.cpp)
LIB = $(wildcard $(LIB_DIR)lib*)
OBJ = $(patsubst $(SRC_DIR)%.cpp, $(OBJ_DIR)%.obj, $(SRC))

BMP = $(wildcard $(RESOURCE_DIR)*.bmp)
PNG = $(wildcard $(RESOURCE_DIR)*.png)


DEBUG_OPTION := -ggdb


$(OBJ_DIR)%.obj : $(SRC_DIR)%.cpp $(HEAD)
	g++ $(DEBUG_OPTION) -c $< -o $@ $(INCUDLE_CONFIG)

pet.exe : $(OBJ) ${OBJ_DIR}resource.o
	g++ -o $@ $^ ${LIBRARY_CONFIG} 


out : pet.exe

BUILDER_DIR = resbuilder
RES_SRC = $(wildcard resbuilder/*.cpp)
$(RES_SRC) : $(BMP) $(PNG) $(BUILDER_DIR)/Resource.h

prepare_res : $(RES_SRC)
	g++ $(DEBUG_OPTION) $^ -o $(BUILDER_DIR)/pre.exe
	./$(BUILDER_DIR)/pre.exe
	objcopy -I binary -O pe-x86-64 -B i386:x86-64 $(BUILDER_DIR)/resource.data ${OBJ_DIR}/resource.o
	g++ -c $(BUILDER_DIR)/Resource.cpp -o $(BUILDER_DIR)/Resource.obj
	ar -rc $(LIB_DIR)/libresource.a $(BUILDER_DIR)/Resource.obj
	copy resbuilder\Resource.h include

.PHONY : out
